<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>分期申请</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
             <div class="clearFix"></div>
			<div class="btnsBox">
                  <span id="deleteBtn" onclick="deleteConfim();" class="sq-button sq-button-round">删除</span>
                  <span id="addBtn"  class="sq-button sq-button-round">新增</span>
                  <input type="hidden" id="prjId" value="${prjId}">
            </div>
        </form>
    </div>
    <div id="intoLigerGrid" class="sq-grid"></div>
    <div id="addMember_Html" style="display:none">
	    <div id="grid" class="sq-grid"></div>
		<div class="btnsBox" style="text-align: center;">
	  	<span id="selectBtn" class="sq-button sq-button-round"></i>确定</span>
    </div>                            
</div>
</div>

<script type="text/javascript">
	var grid = null;
	var detailFlag = '${detailFlag}';
	var prjId = $("#prjId").val();
	
	var prjPrdId='${prjPrdId}';
	var prdFlag='${prdFlag}';
	var prdgrid = null;
	var ywParam = '${ywParam}';
	var buOrgCd = '${buOrgCd}';
	$(function(){
		initGrid();
	 	if(detailFlag=="true"){
	    	$("#addBtn").hide();
	    	$("#deleteBtn").hide();
	    } 
	});

	//初始化表单数据
	function initGrid(){
		 grid = $("#intoLigerGrid").ligerGrid({
			 url:'<%=path%>/inscare/insapplication/initData.do?prjId='+prjId,
			 method:"get",
			 isSingleCheck: true,
		     parms:"",
			 columns: [
                {display: '申请编号', name: 'id', width: 120, enabledSort: true,
                	render:function(rowdata,rowindex,value,column) {
                    var q = '';
                     	q = '<a  href="javascript:detail(';
                        q += "'" + rowdata.id + "'";
                        q += ')">'+value+'</a>';
		    		  return  q;
		    	  }
                },
                {display: '被保人名称', name: 'insPerNm', width: 100, enabledSort: true},
                {display: '车辆型号', name: 'vehicleType', width: 120, enabledSort: true},
                {display: '商业保费', name: 'busAmt', width: 180, enabledSort: true,render: renderAmt},
                {display: '交强险保费', name: 'jqAmt', width: 100, enabledSort: true,render: renderAmt},
                {display: '车架号', name: 'vin', width: 180, enabledSort: true },
                {display: '车牌号', name: 'plateNo', width: 180, enabledSort: true },
                {display: '发动机号', name: 'engineNo', width: 180, enabledSort: true},
                {display: '操作',width:180,align:'center',enabledSort:true,
                	 render:function(rowdata,rowindex,value,column) {
                         var q = '';
                            if(detailFlag!="true"){
                            	 q = '<a class="sq-button-hasicon" href="javascript:modify(';
                                 q += "'" + rowdata.id + "'";
                                 q += ')"><i class="sqBtnIco_4"></i>修改</a>';
                            }
                        	
			    		  return  q;
			    	  }
                }
              
                //  getGridOperColumnContent()
            ],
		     pageSize:10,
		     root:'rows',
	         record:'total',
	         hideLoadButton : true,
	         width: '100%',
	         height:'100%',
	         heightDiff:-2,
	         checkbox:true,
	         rownumbers:true,
	         onSelectRow: function (rowdata, rowid, rowobj) {
             }
		 });
		 grid = liger.get("intoLigerGrid");
		 grid.setHeight(500);
	}
	//格式化为人民币格式
    function renderAmt(rowdata, rowindex, value) {
    	if (StringUtils.isEmpty(value)) {
              return h = "0";
        }
        var h = "￥" + FormatMoney(value)
        return h;
    }
	

	



    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

    //格式化时间去掉  00000
    function render(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

	
  
    function add() {
    	var prjId = $("#prjId").val();
    	checkPrject(prjId);
    }
    function checkPrject(prjId){
        $.ajax({
            url: '<%=path%>/inscare/insapplication/checkProject.do',
            type: 'get',
            data: {
            	prjId:prjId
            },
           
            dataType: "json",
            success: function (msg) {   //提交成功后自动执行的处理函数，参数data就是服务器返回的数据。
                if (msg.success == 1) {
                    $.ligerDialog.SQopen({
                        width: 800,
                        height: 400,
                        title: '选择项目产品信息',
                        url: '<%=path%>/inscare/insapplication/toSelectPrjPrd.do?prjId='+prjId ,
                    });
                } else {
                    top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "warning"});
                    return false;
                }
            },
            error: function (data, status, e) {
            	 top.$.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
            	 return false;
            }
        });
    }
    
    //删除
    function deleteConfim(){
    	var data = grid.getData();
		var fileSelect = grid.getSelectedRows();
		if(fileSelect.length == 0){
			top.$.ligerDialog.SQalert({content:"您没有勾选任何产品，请选择",SQ_type: "error"});
			return false;
		}
    	$.ligerDialog.confirm("确认删除么？",function(flag){
    		if(false == flag)return;
    		
			 $.ajax({
	             type: 'get',
	             dataType: 'json',
	             data: {
	            	 applyId: fileSelect[0].id
	             },
	             url: '<%=path%>/inscare/insapplication/deleteByApplyId.do',
	             //我们通常会在代码中增加对beforsSend时间的处理，比方点击按钮后立刻给出一个‘请求发送中，请稍后的’提示
	             beforeSend: function () {
	                 //等会对话框
	                 wait_dialog = $.ligerDialog.SQalert({
	                     content: LogUtils.LOG_CMM_DATA_LOADING,
	                     SQ_type: "waitting"
	                 });
	             },
	             success: function (msg) {
	                 wait_dialog.close();
	                 //如果返回成功
	                 if (msg.success == 1) {
	                     $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
	                     grid.reload();
	                 } else {
	                     $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
	                 }
	             }
	         })
    	})
    }
 	
    function modify(applyId){
    	 var callback = function () {
    		 initGrid();
         };

		Add_navTab( 'applyId'+applyId,'分期申请修改','<%=path%>/inscare/insapplication/toModifyPage.do?id='+applyId ,callback);
    }
    function detail(applyId){
		Add_navTab( 'applyId'+applyId,'申请单详情','<%=path%>/inscare/insapplication/toAgentDetail.do?applicationId='+applyId);
    }

    $("#addBtn").click(function(event) {
    	initPrdGrid();
        $.ligerDialog.SQopen({
            // cls: 'noBorder_Dialog',
            width: 750,
            title : '选择项目产品信息',
            target: $("#addMember_Html")
        });
    });
    
  //初始化列表
	function initPrdGrid(){
		var manager = null;
		var params = {};
	
		params.prjId = prjId;
		manager =  $("#grid").ligerGrid({
	    	url: '<%=path%>/project/prjprddtl/initList.do',
	    	method : 'get',
	    	parms:params,
	        columns: [
	            { display: '产品名称', name: 'prdNm', minWidth: 100,
	             	
	            	enabledSort:true},
	            { display: '车辆型号', name: 'prdMdl', minWidth: 140,enabledSort:true},
	            getPaySchNoColumn(),
	            { display: '挂靠公司名称', name: 'lnkCompNm', minWidth: 100 ,
	            	render: function (rowdata, rowindex, value, column) { 
	            		 value ==null?"":value;
	            		var h = '';
	            		if(value){
	            		if(rowdata.prjLnkCompVO){
	            		  if(rowdata.prjLnkCompVO.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON||rowdata.prjLnkCompVO.audStsCd==FlowConstant.FLOW_CHECK_STATE_IN){
		                    	h+='<i class="ico_flasher"></i>';
		                    }
	            		}
	            		    h+='<a href="javascript:detailBtn(';
	                        h+="'"+rowdata.lnkCompId+"'";
	                        h+=')">'+value+'</a>'
	                        
	            		}
	                        return h;
	                        
	            		},
	            	enabledSort:true},
	            	  { display: '合格证编号', name: 'certNo', 
	            		render: function (rowdata, rowindex, value, column) { 
		            		var h = '';
	            			if(value){
		            		    h+='<a  href="javascript:detailVehBtn(';
		                        h+="'"+rowdata.actPrdId+"',";
		                        h+="'"+rowdata.id+"'";
		                        h+=')">'+value+'</a>'
	            			}
		            		   
		                        return h;
		            		},
	            		minWidth: 180, enabledSort:true},
	            	  { display: 'GPS卡号1', name: 'gpsCardNo', minWidth: 160, editor: {type: 'text'}, enabledSort:true},
	            	  { display: 'GPS卡号2', name: 'gpsCardNo2', minWidth: 160,editor: {type:'text'}, enabledSort:true},
	            	  getVinColumn(),
	            	  
	            
	        ],
	        pageSize:100,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'90%',
	        heightDiff:-2,
	        checkbox:true,
	        isSingleCheck: true,
	        allowUnSelectRow: true,
            alternatingRow: true,
	        rownumbers:true,
	       // enabledEdit: true,
	        usePagerOnLessPagesize: true,
	    });
		prdgrid = liger.get("grid");
		prdgrid.setHeight(90);
		
	}
  
	$("#selectBtn").click(function(){
		var data = prdgrid.getData();
		var fileSelect = prdgrid.getSelectedRows();
		if(fileSelect.length == 0){
			top.$.ligerDialog.SQalert({content:"您没有勾选任何产品，请选择",SQ_type: "error"});
			return false;
		}
		var prjPrdDtlId = fileSelect[0].id
		checkData(prjPrdDtlId);
		
	})
	function getPaySchNoColumn(){
		var column;
		if(ywParam == 1){
			column ={ display: '支付表号', name: 'paySchNo', minWidth: 140,enabledSort:true,
					render: function (rowdata, rowindex, value){
						if(StringUtils.isEmpty(rowdata.paySchNo)){
							return "";
						}else{
							return rowdata.paySchNo;
						}
                	} 
			};
		}
		return column;
	}
	
	//获取逾期天数列
	function getVinColumn(){
		var column;
		if(detailFlag!="true"){
			column ={ display: 'VIN', name: 'vin', minWidth: 160, editor: {type: 'text'}, enabledSort:true,
          		  render: function (rowdata, rowindex, value){
                        return rowdata.vin;
                	}  
          	  };
			
		}else{
			column ={ display: 'VIN', name: 'vin', minWidth: 160,  enabledSort:true,
	          		  render: function (rowdata, rowindex, value){
	                		var h="";
	                		if(StringUtils.isNotEmpty(rowdata.vin)){
	                			h='<a class="sq-button-hasicon" href="javascript:toRePrjPageList(';
	                            h+="'vin','"+rowdata.vin+"'";
	                            h+=')"><i class="sqBtnIco_1"></i></a>';
	                            h+='&nbsp;&nbsp;&nbsp;&nbsp;'+rowdata.vin;
	                        }else{
	                        	h = rowdata.vin;
	                        }
	                        return h;
	                	}  
	          	  };
		}
		return column;
	}
	
	//校验是否已做保险分期
	function checkData(prjPrdDtlId){
		 $.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{
	    			prjPrdDtlId:prjPrdDtlId
	    		},
	    		async: false,
	    		url: "<%=path%>/inscare/insapplication/checkData.do",
	    		beforeSend: function(){
	  	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	  	     	},
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){
	    				checkVehon(prjPrdDtlId);
	    				return true;
	    			 }else{
	    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    				 return false;
	    			 }
	    		},
	    		error:function(){
	    			 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
    				 return false;
	    		}
	    	});
	}
	//校验是否有合格证信息
	function checkVehon(prjPrdDtlId){
		 $.ajax({
	    		type: 'get',
	    		dataType:'json',
	    		data:{
	    			prjPrdDtlId:prjPrdDtlId
	    		},
	    		async: false,
	    		url: "<%=path%>/inscare/insapplication/checkVehon.do",
	    		beforeSend: function(){
	  	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	  	     	},
	    		success:function(msg){
	    			 wait_dialog.close();
	    			 if(msg.success == 1){
	    				 var callback = function () {
	    					 initGrid();  
	    		         };
	    		         $.ligerDialog.hide();
	    				Add_navTab("fqApplication"+prjPrdDtlId, "分期申请", '<%=path%>/inscare/insapplication/toTabAddPage.do?prjPrdDtlId='+prjPrdDtlId, callback);
	    				return true;
	    			 }else{
	    				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	    				 return false;
	    			 }
	    		},
	    		error:function(){
	    			 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
    				 return false;
	    		}
	    	});
	}	       
</script>

</body>
</html>
